package org.dyndns.opendemogroup.optimizer.problems;

import java.util.Random;

import org.dyndns.opendemogroup.optimizer.IOptimizationProblem;

/**
 * Also known as <i>n-sphere</i>, this is a minimization problem where all
 * points should be at zero for the global minimum of zero.
 */
public class HyperSphere extends EvolutionStrategyBase
{

	public HyperSphere ( int memberSize )
	{
		super ( memberSize );
	}

	/**
	 * @see IOptimizationProblem#computeFitness(Random)
	 */
	@Override
	public double computeFitness ( Random randomSource )
	{
		double fitness = 0.0;
		for ( int i = 0; i < partSize; i++ )
		{
			fitness += ( values[i] * values[i] );
		}
		return fitness;
	}

	/**
	 * @see IOptimizationProblem#isMaximizing()
	 */
	@Override
	public boolean isMaximizing ( )
	{
		return false;
	}

	/**
	 * @see EvolutionStrategyBase#determineParameterMaximums()
	 */
	@Override
	protected double[] determineParameterMaximums ( )
	{
		double[] result = new double[partSize];
		for ( int i = 0; i < partSize; i++ )
		{
			result[i] = 5.0;
		}
		return result;
	}

	/**
	 * @see EvolutionStrategyBase#determineParameterMinimums()
	 */
	@Override
	protected double[] determineParameterMinimums ( )
	{
		double[] result = new double[partSize];
		for ( int i = 0; i < partSize; i++ )
		{
			result[i] = -5.0;
		}
		return result;
	}

	/**
	 * @see EvolutionStrategyBase#determineSigmaMaximums()
	 */
	@Override
	protected double[] determineSigmaMaximums ( )
	{
		double[] result = new double[partSize];
		for ( int i = 0; i < partSize; i++ )
		{
			result[i] = 0.5;
		}
		return result;
	}

	/**
	 * @see EvolutionStrategyBase#determineSigmaMinimums()
	 */
	@Override
	protected double[] determineSigmaMinimums ( )
	{
		double[] result = new double[partSize];
		for ( int i = 0; i < partSize; i++ )
		{
			result[i] = -0.5;
		}
		return result;
	}

}
